<?php 
	
	class Admin extends CI_Controller
	{
		var $data;
		var $data_type;
		var $menu_data;

		function __construct()
		{
			parent::__construct();

			$this->data['title'] = 'Admin Template';

			$this->data_type = 'product';

			// Left Menu Data
			// $this->menu_data = array(
			// 		'Products'	=> site_url('admin/products'),
			// 		'Order'	=>	site_url('admin/orders'),
			// 		'Member'	=>	site_url('admin/members'),
			// 	);

			$this->menu_data = array(
					'News Type'	=>	site_url('admin/new_types'),
					'News'	=>	site_url('admin/news'),
					'Member'	=>	site_url('admin/members'),
				);
		}


		function index()
		{
			$this->loadTemplatePart('index');			

			// load view
			$this->load->view('admin/index',$this->data);
		}


		/////////////////////// COMMON FUNCTION ////////////////////
		function loadTemplatePart($action = '')
		{
			$this->data['header'] = $this->loadHeader();
			$this->data['left'] = $this->loadLeftMenu();			
			$this->data['main'] = $this->loadMainPart($action);
		}

		function loadHeader()
		{
			return $this->load->view('admin/header', $this->data);
		}

		function loadLeftMenu()
		{
			
			$template = '<ul>#data</ul>';

			$menu = '';

			// Products Website
			switch ( $this->data_type ) 
			{
				case 'product':
					foreach ($this->menu_data as $title => $href) 
					{
						$menu .= "<li>".anchor($href,$title)."</li>";
					}		
					break;
				
				default:
					
					break;
			}

			$this->data['menu'] = str_replace('#data', $menu, $template);

			return $this->load->view('admin/left', $this->data);
		}

		function loadMainPart($action = '')
		{
			// Product Website
			switch ( $action ) 
			{
				case 'value':
					
					break;
				
				default:
					// index
					

					// news
					$this->load->model('Gs_new_news_model');
					$news = $this->Gs_new_news_model->select();

					if( empty($news) )
					{
						$this->data['news'] = 'Empty news !';
					}
					
					break;
			
			return $this->load->view('admin/main', $this->data);
		}
	}
